<?php if(!isset($data['listhd'])){?>
<link href="public/jquery/jquery.datepick.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="public/jquery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="public/jquery/jquery.datepick.js"></script>
<script type="text/javascript" src="public/jquery/jquery.datepick-vi.js"></script>
<script type="text/javascript">
$(function() {
	$('#popupDatepicker').datepick();
	$('#inlineDatepicker').datepick({onSelect: showDate});
	$('#Datepicker').datepick();
});

function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>

<div id="title_right">
	<p id="title_right_left"></p>
	<div id="title_right_center">
		<p class="chu_title">DOANH THU</p>
	</div>
	<p id="title_right_right"></p>
</div>

<form  name="doanhthu" method="post" action="">
  <table width="763" border="1" cellspacing="2" cellpadding="2" style="margin-top: 10px">
    <tr>
      <td align="center">Từ ngày:</td>
      <td>
      <input type="text" name="tungay" id="popupDatepicker" /></td>
      <td align="center">Đến ngày:</td>
      <td><input type="text" name="denngay" id="Datepicker" /></td>
    </tr>
     <tr>
    <td colspan="4" align="right"><input type="submit" name="xem" id="xem" value="Xem" /></td>
    </tr>
  </table>
</form>
<?php 
}
else{	
	?>
	
		<p align="center" style="margin: 10px;font-size: 25px">BÁO CÁO DOANH THU</p>
		<p align="center" style="margin:10px">Từ ngày: <?php echo ($_POST['tungay']);?> đến ngày : <?php echo $_POST['denngay'];?> </p>
<table class="table">
	<tr class="mau2">
		<td>Tên mặt hàng</td>
		<td>Ngày bán</td>
		<td>Giá bán</td>
		<td>Số lượng bán</td>
		<td>Thành tiền</td>
	</tr>
<?php 
$tongtien=0;
$i=1;
foreach ($data['listhd'] as $key => $hd){
	
	if(is_array($data['listcthd'])){
		foreach ($data['listcthd'] as $cthd){
			if($hd['MaHD'] == $cthd['MaHD']){
				if(is_array($data['listmh'])){
					foreach ($data['listmh'] as $mh){
						if($cthd['MaMH'] == $mh['MaMH']){
							if($i%2==0){
								echo "<tr class='mau'>";
							}else
							{
								echo "<tr>";
							}
							
				?>
					<td><?php echo $mh['TenMH'];?></td>
					<td><?php echo $hd['NgayLap'];?></td>
					<td><?php echo number_format($cthd['DonGiaBan']);?></td>
					<td><?php echo $cthd['SoLuongBan'];?></td>
					<?php $thanhtien=$cthd['DonGiaBan']*$cthd['SoLuongBan'];?>
					<td><?php echo number_format($thanhtien);?></td>
					<?php $tongtien+=$thanhtien;?>
					</tr>
					<?php 	}

					}
				}
			}
		}
	}
	?>

	<?php }?>
					<tr>
					<td colspan="4" align="right">Tổng tiền</td>
						<td><?php echo number_format($tongtien);?></td>
					</tr>		
</table>
	
<?php }

?>